package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmht.beike.biz.HealthMovementBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.THealthmovement;

public class HealthMovementBizImpl extends BaseBizImpl implements
		HealthMovementBiz {

	public THealthmovement findById(Serializable id) {
		
		return (THealthmovement)this.getHealthMovementDAO().findById(THealthmovement.class, id);
		
	}

	public THealthmovement findByStudentId(Serializable studentId) {
		String hql = "from THealthmovement t where studentId ="+studentId+" order by t.id desc";
		List<THealthmovement> list = this.getHealthMovementDAO().findByHQLObj(hql);
		if(list!=null&&list.size()>0){
			return list.get(0);
		}
		return null;
	}

	public boolean saveHealthmovement(THealthmovement healthmovement) {
		try{
			this.getHealthMovementDAO().saveObj(healthmovement);
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public boolean updateHealthmovement(THealthmovement healthmovement) {
		try{
			this.getHealthMovementDAO().updateObj(healthmovement);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	public static void main(String [] args){
		ApplicationContext cxt;
		cxt = new ClassPathXmlApplicationContext(new String[]{"spring/spring.xml","spring/spring_dao.xml","spring/spring_beike.xml"});
		HealthMovementBizImpl biz = (HealthMovementBizImpl)cxt.getBean("healthMovementBizTag");
		
		
		THealthmovement healthmovement = new THealthmovement();
		healthmovement.setStudentId(3);
		
		biz.saveHealthmovement(healthmovement);
		
		/*THealthmovement healthmovement = biz.findByStudentId(11);
		System.out.println(healthmovement.getStudentId());*/
		
	}

	public List<THealthmovement> findByStudent(Serializable studentId,String startTime, String endTime) {
		String where = "";	
		
	 	
		if(!"".equals(startTime)&&null!=startTime){
			where +="and t.ctime >=  '"+startTime+"' ";
		}
		if(!"".equals(endTime)&&null!=endTime){
			where +="and t.ctime <= '"+endTime+"' ";
		}
		String hql = "from THealthmovement t where studentId ="+studentId+" "+where+" order by t.id desc";
		List<THealthmovement> list = this.getHealthMovementDAO().findByHQLObj(hql);
		
		return list;
	}

	
}
